package com.xjrsoft.common.querys;

import com.baomidou.mybatisplus.generator.config.querys.OracleQuery;

public class XjrOracleQuery extends OracleQuery {

    @Override
    public String tableFieldsSql() {
        return "SELECT A.COLUMN_NAME, CASE WHEN A.DATA_TYPE = 'NUMBER' THEN A.DATA_PRECISION " +
                "ELSE A.CHAR_LENGTH END MAX_LENGTH, A.DATA_TYPE, B.COMMENTS, " +
                "DECODE(C.POSITION, '1', 'PRI') KEY FROM ALL_TAB_COLUMNS A INNER " +
                "JOIN ALL_COL_COMMENTS B ON A.TABLE_NAME = B.TABLE_NAME AND A.COLUMN_NAME " +
                "= B.COLUMN_NAME AND B.OWNER = '#schema' LEFT JOIN ALL_CONSTRAINTS D ON D.TABLE_NAME " +
                "= A.TABLE_NAME AND D.CONSTRAINT_TYPE = 'P' AND D.OWNER = '#schema' " +
                "LEFT JOIN ALL_CONS_COLUMNS C ON C.CONSTRAINT_NAME = D.CONSTRAINT_NAME " +
                "AND C.COLUMN_NAME = A.COLUMN_NAME AND C.OWNER = '#schema' WHERE A.OWNER " +
                "= '#schema' AND A.TABLE_NAME = '%s' ORDER BY A.COLUMN_ID ";
    }
}
